package com.example.teamilkmall.service.Impl;

import com.example.teamilkmall.controller.exception.ErrorsEnum;
import com.example.teamilkmall.controller.exception.LoginException;
import com.example.teamilkmall.entity.Account;
import com.example.teamilkmall.entity.AdminInfo;
import com.example.teamilkmall.entity.TeaInfo;
import com.example.teamilkmall.mapper.AdminInfoMapper;
import com.example.teamilkmall.service.AdminInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminInfoServiceImpl implements AdminInfoService {
    private final AdminInfoMapper adminInfoMapper;

    public AdminInfoServiceImpl(AdminInfoMapper adminInfoMapper) {
        this.adminInfoMapper = adminInfoMapper;
    }

    @Override
    public PageInfo<AdminInfo> listAdmin(Integer pageSize, Integer pageNum, String name) {
        List<AdminInfo> list = adminInfoMapper.listAdminInfo(pageSize,pageNum,name);
        PageInfo<AdminInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<AdminInfo> listAdminInfoAll() {
        return adminInfoMapper.listAdminInfoAll();
    }

    @Override
    public void updateAdmin(AdminInfo adminInfo) {
        adminInfoMapper.updateAdminInfo(adminInfo);
    }

    @Override
    public void deloneAdmin(Integer id) {
        adminInfoMapper.deloneAdmin(id);
    }

    @Override
    public void addAdmin(AdminInfo adminInfo) {
        adminInfoMapper.addAdmin(adminInfo);
    }

    @Override
    public AdminInfo auto(AdminInfo adminInfo) {
        AdminInfo adminInfo1 = adminInfoMapper.getAdminInfo(adminInfo);
        if (adminInfo != null){
            return adminInfo1;
        }
        throw new LoginException(ErrorsEnum.LOGIN_EXCEPTION);
    }


}
